<?php

namespace backend\models;

use yii\base\Model;
use yii\data\ActiveDataProvider;
use backend\models\Major;

/**
 * MajorSearch represents the model behind the search form of `backend\models\Major`.
 */
class MajorSearch extends Major
{
    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['ID', 'XXID', 'BMID'], 'integer'],
            [['ZYDM', 'ZYMC', 'ZYJC', 'BXZYBH', 'ZYJS', 'KSSJ', 'CXSJ', 'ZYMLBB', 'ZYLB', 'ZYFX', 'ZSLB', 'XZ', 'JXXS', 'SFGK', 'SFSN', 'ZSZG', 'ZT'], 'safe'],
            [['ZXF', 'BXXF'], 'number'],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        $query = Major::find();

        // add conditions that should always apply here

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }

        // grid filtering conditions
        $query->andFilterWhere([
            'ID' => $this->ID,
            'XXID' => $this->XXID,
            'BMID' => $this->BMID,
            'KSSJ' => $this->KSSJ,
            'CXSJ' => $this->CXSJ,
            'ZXF' => $this->ZXF,
            'BXXF' => $this->BXXF,
        ]);

        $query->andFilterWhere(['like', 'ZYDM', $this->ZYDM])
            ->andFilterWhere(['like', 'ZYMC', $this->ZYMC])
            ->andFilterWhere(['like', 'ZYJC', $this->ZYJC])
            ->andFilterWhere(['like', 'BXZYBH', $this->BXZYBH])
            ->andFilterWhere(['like', 'ZYJS', $this->ZYJS])
            ->andFilterWhere(['like', 'ZYMLBB', $this->ZYMLBB])
            ->andFilterWhere(['like', 'ZYLB', $this->ZYLB])
            ->andFilterWhere(['like', 'ZYFX', $this->ZYFX])
            ->andFilterWhere(['like', 'ZSLB', $this->ZSLB])
            ->andFilterWhere(['like', 'XZ', $this->XZ])
            ->andFilterWhere(['like', 'JXXS', $this->JXXS])
            ->andFilterWhere(['like', 'SFGK', $this->SFGK])
            ->andFilterWhere(['like', 'SFSN', $this->SFSN])
            ->andFilterWhere(['like', 'ZSZG', $this->ZSZG])
            ->andFilterWhere(['like', 'ZT', $this->ZT]);

        return $dataProvider;
    }
}
